package common

import (
	"crypto/sha256"
	"encoding/hex"
	"math/rand"
	"time"
)

//@comment 生成用户uid
func GenUserUid() uint64 {
	// 循环500次
	uid := uint64(0)
	for i := 0; i < 500; i++ {
		uid = (uid + uint64(RandInt(0, 0xFFFFFFFFFFFF))) % 100000000000
	}
	return uid
}

//@comment 获取指定范围的整数型随机数
func RandInt(_min int64, _max int64) int64 {
	rand.Seed(time.Now().UnixNano())
	return (rand.Int63() % (_max - _min)) + _min
}

// 加密用户的密码,密码从前端传过来应该是经过了base64处理的
func EncryptPassword(salt, pass string) string {
	s := salt + pass
	h := sha256.New()
	h.Write([]byte(s))
	return hex.EncodeToString(h.Sum(nil))
}
